package swing;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.WindowConstants;

import ViewObjects.ItemAlmacenView;
import ViewObjects.ProveedorView;

import rmi.ProxyModeloConcreto;

import controlador.Controlador;
import controlador.ControladorAdmProveedores;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class StockBaja extends Vista{
	private JLabel jLabelidOc;
	private JLabel jLabelMensaje;
	private JButton jverificar;
	private JButton jButtonCancelar;
	private JButton jButtonBajaStock;
	private JTextField jTextFieldidOc;

	public StockBaja(){
		super();
		initGUI();
	}
	
	@Override
	public void actualizar() {
		// TODO Auto-generated method stub
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			this.setTitle("Baja de Stock");
			this.setVisible(true);

			{
				jLabelidOc = new JLabel();
				getContentPane().add(jLabelidOc, BorderLayout.CENTER);
				jLabelidOc.setText("Nro O.C. : ");
				jLabelidOc.setBounds(17, 29, 145, 27);
			}
			{
				jTextFieldidOc = new JTextField();
				getContentPane().add(jTextFieldidOc);
				jTextFieldidOc.setBounds(100, 31, 94, 23);
			}
			{
				jButtonBajaStock = new JButton();
				getContentPane().add(jButtonBajaStock);
				jButtonBajaStock.setText("Baja Stock");
				jButtonBajaStock.setBounds(17, 144, 111, 23);
				jButtonBajaStock.setEnabled(true);
				jButtonBajaStock.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						bajaStock();
						}	
					} 
				);
			}
			{
				jButtonCancelar = new JButton();
				getContentPane().add(jButtonCancelar);
				jButtonCancelar.setText("Cancelar");
				jButtonCancelar.setBounds(157, 144, 91, 23);
				jButtonCancelar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						dispose();
						}	
					} 
				);
			}
			{
				jLabelMensaje = new JLabel();
				getContentPane().add(jLabelMensaje);
				jLabelMensaje.setBounds(17, 111, 295, 21);
			}
			{
				jverificar = new JButton();
				getContentPane().add(jverificar);
				jverificar.setText("Verificar");
				jverificar.setBounds(206, 32, 91, 21);
				jverificar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						buscarOc();
					}

					private void buscarOc() {
						ProxyModeloConcreto p = (ProxyModeloConcreto) controlador.getModelo();
						int nroOc = p.buscarOc(Integer.parseInt(jTextFieldidOc.getText()));
						
						if (nroOc!=0){
							jLabelMensaje.setText("La Oc Fue Verificada");
							
						} else {
							jLabelMensaje.setText("La Oc no existe");
							jTextFieldidOc.setText("");
						}
						
					}
				});
			}
			{
				this.setSize(333, 216);
			}
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
/*
	private void buscarOc() {
		ProxyModeloConcreto p = (ProxyModeloConcreto) controlador.getModelo();
		ProveedorView prov = p.consultar_proveedor(Integer.parseInt(jTextFieldidProveedor.getText()));
		if (prov!=null){
			jTextFieldTelefono.setText(prov.getTelefono());
			jTextFieldDireccion.setText(prov.getDireccion());
			jTextFieldRazonSocial.setText(prov.getRazonSocial());
			jTextFieldidProveedor.setEnabled(false);
			jButtonBajaProveedor.setEnabled(true);
		} else {
			jLabelMensaje.setText("La Oc no Existe");
			jButtonBajaStock.setEnabled(false);
		}
	}
	*/
	private void bajaStock() {
		ProxyModeloConcreto p = (ProxyModeloConcreto) controlador.getModelo();
		p.baja_Stock(Integer.parseInt(jTextFieldidOc.getText()));
		jLabelMensaje.setText("Se dio de baja la Oc y sus Items");
	}
	/**
	* This method should return an instance of this class which does 
	* NOT initialize it's GUI elements. This method is ONLY required by
	* Jigloo if the superclass of this class is abstract or non-public. It 
	* is not needed in any other situation.
	 */
	public static Object getGUIBuilderInstance() {
		return new StockBaja(Boolean.FALSE);
	}
	
	/**
	 * This constructor is used by the getGUIBuilderInstance method to
	 * provide an instance of this class which has not had it's GUI elements
	 * initialized (ie, initGUI is not called in this constructor).
	 */
	public StockBaja(Boolean initGUI) {
		super();
	}
}
